package ReviewAlgorithms.greedyThought;

public class CheckPossibility {
    public static void main(String[] args) {
        int[] num = {3,4,5,2,6,5};
        System.out.println(checkPossibility(num));
    }
    public static boolean checkPossibility(int[] nums) {
        if (nums == null || nums.length <= 2){
            return true;
        }
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i - 1 >= 0 && nums[i] < nums[i - 1]){
                count ++;
                if (i - 2 >= 0 && nums[i] < nums[i - 2] && i + 1 < nums.length && nums[i - 1] > nums[i + 1]){
                    return false;
                }
            }
            if (count > 1){
                return false;
            }
        }
        return true;
    }
}
